﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Models;
using DAL;

namespace BLL
{
    /// <summary>
    /// 权限业务类
    /// </summary>
    public class SysRightManager
    {
        private SysRightService sysRightService = new SysRightService();

        #region 角色管理
        /// <summary>
        /// 获取所有的角色
        /// </summary>
        public List<AdminRoles> GetAllRoles()
        {
            return sysRightService.GetAllRoles();
        }

        /// <summary>
        /// 新增角色
        /// </summary>
        /// <param name="roleName"></param>
        /// <param name="roleDesc"></param>
        /// <returns></returns>
        public int AddRole(string roleName, string roleDesc)
        {
            return sysRightService.AddRole(roleName, roleDesc);
        }

        /// <summary>
        /// 修改角色
        /// </summary>
        /// <param name="roleId"></param>
        /// <param name="roleName"></param>
        /// <param name="roleDesc"></param>
        /// <returns></returns>
        public int ModifyRole(int roleId, string roleName, string roleDesc)
        {
            return sysRightService.ModifyRole(roleId,roleName, roleDesc);
        }

        /// <summary>
        /// 删除角色
        /// </summary>
        /// <param name="roleName"></param>
        /// <param name="RoleDesc"></param>
        /// <returns></returns>
        public int DeleteRole(int roleId)
        {
            return sysRightService.DeleteRole(roleId);
        }
        #endregion

        #region 管理员
        /// <summary>
        /// 获取所有管理员用户
        /// </summary>
        /// <returns></returns>
        public List<SysAdmin> GetAllAdmin()
        {
            return sysRightService.GetAllAdmin();
        }

        /// <summary>
        /// 添加管理员
        /// </summary>
        /// <param name="sysAdmin"></param>
        /// <returns></returns>
        public int AddAdmin(SysAdmin sysAdmin)
        {
            return sysRightService.AddAdmin(sysAdmin);

        }

        /// <summary>
        /// 修改管理员姓名
        /// </summary>
        /// <param name="adminId"></param>
        /// <param name="adminName"></param>
        /// <returns></returns>
        public int ModifyAdminName(string adminId, string adminName)
        {
            return sysRightService.ModifyAdminName(adminId, adminName);
        }

        /// <summary>
        /// 修改管理员姓名
        /// </summary>
        /// <param name="adminId"></param>
        /// <param name="roleId"></param>
        /// <returns></returns>
        public int ModifyAdminRole(string adminId, string roleId)
        {
            return sysRightService.ModifyAdminRole(adminId, roleId);
        }

        /// <summary>
        /// 删除管理员
        /// </summary>
        /// <param name="adminId"></param>
        /// <returns></returns>
        public int DeleteAdmin(string adminId)
        {
            return sysRightService.DeleteAdmin(adminId);
        }

        /// <summary>
        /// 禁用账号
        /// </summary>
        /// <param name="adminId"></param>
        /// <returns></returns>
        public int BidAdmin(string adminId)
        {
            return sysRightService.ModifyAdminStatus(adminId, 0);
        }


        /// <summary>
        /// 启用账号
        /// </summary>
        /// <param name="adminId"></param>
        /// <returns></returns>
        public int AllowAdmin(string adminId)
        {
            return sysRightService.ModifyAdminStatus(adminId, 1);
        }
        #endregion

        #region 权限管理:获取权限目录树
        /// <summary>
        /// 获取以及权限
        /// </summary>
        /// <returns></returns>
        public List<FirstMenu> GetFirstMenus()
        {
            return sysRightService.GetFirstMenus();
        }

        /// <summary>
        /// 根据一级菜单Id获取对应二级菜单
        /// </summary>
        /// <returns></returns>
        public List<SecondMenu> GetSecondMenus(int firstMenuId)
        {
            return sysRightService.GetSecondMenu(firstMenuId);
        }


        /// <summary>
        /// 根据二级菜单Id获取对应权限点
        /// </summary>
        /// <param name="secondMenuId"></param>
        /// <returns></returns>
        public List<RightList> GetRightCode(int secondMenuId)
        {
            return sysRightService.GetRightCode(secondMenuId);
        }
        #endregion

        #region 查询角色权限
        /// <summary>
        /// 获取一级菜单
        /// </summary>
        /// <param name="roleId"></param>
        /// <returns></returns>
        public List<FirstMenu> GetRoleFirstMenus(string roleId)
        {
            return sysRightService.GetRoleFirstMenus(roleId);
        }

        /// <summary>
        /// 根据一级菜单Id获取对应二级菜单
        /// </summary>
        /// <param name="firstMenuId"></param>
        /// <param name="roleId"></param>
        /// <returns></returns>
        public List<SecondMenu> GetRoleSecondMenu(int firstMenuId, string roleId)
        {
            return sysRightService.GetRoleSecondMenu(firstMenuId, roleId);
        }


        /// <summary>
        /// 根据二级菜单Id获取对应权限点
        /// </summary>
        /// <param name="secondMenuId"></param>
        /// <returns></returns>
        public List<RightList> GetRoleRightCode(int secondMenuId, string roleId)
        {
            return sysRightService.GetRoleRightCode(secondMenuId, roleId);
        }
        #endregion

        #region 角色权限设定
        /// <summary>
        /// 查询该角色是否已经具备该权限
        /// </summary>
        /// <param name="roleId"></param>
        /// <param name="rightId"></param>
        /// <returns></returns>
        public bool QueryRoleRightIsExists(string roleId, string rightId)
        {
            return sysRightService.QueryRoleRightIsExists(roleId, rightId);
        }

        /// <summary>
        /// 给角色添加权限
        /// </summary>
        /// <param name="roleId"></param>
        /// <param name="rightId"></param>
        /// <returns></returns>
        public int AddRoleRight(string roleId, string rightId)
        {
            return sysRightService.AddRoleRight(roleId, rightId);
        }

        /// <summary>
        /// 给角色删除权限
        /// </summary>
        /// <param name="roleId"></param>
        /// <param name="rightId"></param>
        /// <returns></returns>
        public int DeleteRoleRight(string roleId, string rightId)
        {
            return sysRightService.DeleteRoleRight(roleId, rightId);
        }
        #endregion
    }
}
